//
//  YXUserDefault.m
//  MockProject
//
//  Created by FanYu on 25/8/2016.
//  Copyright © 2016 niuzhaowang. All rights reserved.
//

#import "YXUserDefault.h"

#define defaults [NSUserDefaults standardUserDefaults]

@implementation YXUserDefault

// Accessibility
+ (BOOL)onlyDownloadOnWiFi {
    return [[defaults objectForKey:@"onlyDownloadOnWiFi"] isEqualToString:@"Y"] ? YES : NO;
}
+ (void)setOnlyDownloadOnWiFi:(BOOL)isOnWiFi {
    if (isOnWiFi) {
        [defaults setObject:@"Y" forKey:@"onlyDownloadOnWiFi"];
    } else {
        [defaults setObject:@"N" forKey:@"onlyDownloadOnWiFi"];
    }
}

// Max similutiouly download amout
+ (NSString *)maxSimultaneouslyNumber {
    return [defaults objectForKey:@"maxSimultaneouslyNumber"];
}
+ (void)setMaxSimultaneouslyNumber:(NSString *)number {
    [defaults setObject:number forKey:@"maxSimultaneouslyNumber"];
}

// version
+ (NSString *)lastVersion {
    return [defaults objectForKey:@"CFBundleShortVersionString"];
}
+ (void)setCurrentVersion:(NSString *)version {
    [defaults setObject:version forKey:@"CFBundleShortVersionString"];
}

// task status
+ (BOOL)isDownloadingTask {
    return [[defaults objectForKey:@"ThereIsDownloadingTask"] isEqualToString:@"Y"] ? YES : NO;
}
+ (void)setIsDownloadingTask:(BOOL)isDownloading {
    if (isDownloading) {
        [defaults setObject:@"Y" forKey:@"ThereIsDownloadingTask"];
    } else {
        [defaults setObject:@"Y" forKey:@"ThereIsDownloadingTask"];
    }
}

// reachability
+ (NetworkStatus)reachability {
    NetworkStatus status = NotReachable;
    if ([[defaults objectForKey:@"Reachability"] isEqualToString:@"NotReachable"]) {
        status = NotReachable;
    } else if ([[defaults objectForKey:@"Reachability"] isEqualToString:@"ReachableViaWiFi"]) {
        status = ReachableViaWiFi;
    } else if ([[defaults objectForKey:@"Reachability"] isEqualToString:@"ReachableViaWWAN"]) {
        status = ReachableViaWWAN;
    }
    return status;
}
+ (void)setReachability:(NetworkStatus)reachability {
    NSString *net = @"";
    if (reachability == NotReachable) {
        net = @"NotReachable";
    } else if (reachability == ReachableViaWiFi) {
        net = @"ReachableViaWiFi";
    } else if (reachability == ReachableViaWWAN) {
        net = @"ReachableViaWWAN";
    }
    [defaults setObject:net forKey:@"Reachability"];
}

// current downing task number
+ (NSInteger)currentDownloadingNumber {
    NSString *num = [defaults objectForKey:@"CurrentDownloadingNumber"];
    return num.integerValue;
}
+ (void)setCurrentDownloadingNumber:(NSInteger)num {
    [defaults setObject:[NSString stringWithFormat:@"%ld", num] forKey:@"CurrentDownloadingNumber"];
}


@end
